package com.example.demo.zaqizabatest;


import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName HashcodeTest
 * @Author lys4134
 * @Date 2021/11/20 14:55:56
 * @Description HashcodeTest
 * @Version 1.0
 **/
public class HashcodeTest {
    public static void main(String[] args) {
//            List<String> list = new ArrayList<String>(10);
//            list.add(2, "1");
//            System.out.println(list.get(0));
        SimpleDateFormat adf = new SimpleDateFormat("yyyyMMddHHmmss");
        long time = Long.parseLong(adf.format(new Date()));
            for (int i =0;i< 5;i++){
                testZhi(time++);
            }
    }

    private static void testZhi(long time) {
        System.out.println(time);
    }

    public static Integer hashCode(String str, Integer multiplier) {
        int hash = 0;
        for (int i = 0; i < str.length(); i++) {
            hash = multiplier * hash + str.charAt(i);
        }
        return hash;
    }

    public static List<Integer> hashCodeList(List<String> strs, Integer multiplier) {
        List<Integer> hashCodeList = new ArrayList<>(strs.size());
        for (String str : strs){
            hashCodeList.add(hashCode(str, multiplier));
        }
        return hashCodeList;
    }

    public static Map<Integer, Integer> hashArea(List<Integer> hashCodeList) {
        Map<Integer, Integer> statistics = new LinkedHashMap<>();
        int start = 0;
        for (long i = 0x80000000; i <= 0x7fffffff; i += 67108864) {
            long min = i;
            long max = min + 67108864;
            // 筛选出每个格子里的哈希值数量，java8流统计；https://bugstack.cn/itstack-demo-any/2019/12/10/%E6%9C%89%E7%82%B9%E5%B9%B2%E8%B4%A7-Jdk1.8%E6%96%B0%E7%89%B9%E6%80%A7%E5%AE%9E%E6%88%98%E7%AF%87(41%E4%B8%AA%E6%A1%88%E4%BE%8B).html
            int num = (int) hashCodeList.parallelStream().filter(x -> x >= min && x < max).count();
            statistics.put(start++, num);
        }
        return statistics;
    }


    private static <T> int indexedBinarySearch(List<String> list, String key) {
        int low = 0;
        int high = list.size()-1;
        while (low <= high) {
            int mid = (low + high) >>> 1;
            Comparable<String> midVal = "";
            int cmp = midVal.compareTo(key);
            if (cmp < 0) {
                low = mid + 1;
            } else if (cmp > 0) {
                high = mid - 1;
            } else {
                return mid; // key found
            }
        }
        return -(low + 1);  // key not found
    }
}



